<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>职位推荐</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        body {
            background-color: #f5f5f5;
            color: #333;
            max-width: 600px;
            margin: 0 auto;
            position: relative;
            min-height: 100vh;
        }

        .app-container {
            padding-bottom: 60px;
            min-height: 100vh;
        }

        .header {
            background-color: #1e88e5;
            color: white;
            padding: 15px;
            text-align: center;
            position: relative;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }

        .search-container {
            padding: 10px 15px;
            background-color: #fff;
            display: flex;
            align-items: center;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }

        .search-input {
            flex: 1;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 20px;
            font-size: 14px;
        }

        .search-button {
            background-color: #1e88e5;
            color: white;
            border: none;
            padding: 10px 15px;
            margin-left: 10px;
            border-radius: 20px;
            cursor: pointer;
        }

        .tab-content {
            display: none;
            padding: 15px;
        }

        .tab-content.active {
            display: block;
        }

        .job-card {
            background-color: white;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }

        .job-title {
            font-size: 18px;
            font-weight: bold;
            color: #1e88e5;
            margin-bottom: 5px;
        }

        .job-company {
            font-size: 14px;
            color: #555;
            margin-bottom: 10px;
        }

        .job-details {
            display: flex;
            justify-content: space-between;
            font-size: 14px;
            color: #777;
        }

        .job-tags {
            margin-top: 10px;
        }

        .job-tag {
            display: inline-block;
            background-color: #e3f2fd;
            color: #1e88e5;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
            margin-right: 5px;
            margin-bottom: 5px;
        }

        .nav-tabs {
            display: flex;
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background-color: white;
            box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
            max-width: 600px;
            margin: 0 auto;
            z-index: 100;
        }

        .nav-tab {
            flex: 1;
            text-align: center;
            padding: 12px;
            color: #777;
            cursor: pointer;
            font-size: 14px;
        }

        .nav-tab.active {
            color: #1e88e5;
            border-top: 2px solid #1e88e5;
        }

        .nav-tab i {
            display: block;
            font-size: 20px;
            margin-bottom: 4px;
        }

        /* 详情页样式 */
        .job-detail-container {
            background-color: white;
            padding: 20px;
            margin: 15px;
            border-radius: 8px;
            box-shadow: 0 1px 5px rgba(0,0,0,0.1);
        }

        .job-detail-header {
            margin-bottom: 20px;
        }

        .job-detail-title {
            font-size: 22px;
            font-weight: bold;
            color: #333;
            margin-bottom: 10px;
        }

        .job-detail-company {
            font-size: 16px;
            color: #555;
            margin-bottom: 8px;
        }

        .job-detail-salary {
            font-size: 18px;
            color: #ff6b6b;
            font-weight: bold;
            margin-bottom: 15px;
        }

        .job-detail-info {
            display: flex;
            flex-wrap: wrap;
            margin-bottom: 15px;
            color: #666;
        }

        .job-detail-info span {
            margin-right: 15px;
            margin-bottom: 5px;
        }

        .job-description {
            line-height: 1.6;
            color: #555;
        }

        .job-requirements {
            margin-top: 20px;
            line-height: 1.6;
            color: #555;
        }

        .apply-button {
            background-color: #1e88e5;
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 6px;
            width: 100%;
            font-size: 16px;
            margin-top: 20px;
            cursor: pointer;
        }

        .apply-button:hover {
            background-color: #1976d2;
        }

        .back-button {
            position: absolute;
            left: 15px;
            top: 15px;
            color: white;
            font-size: 18px;
            cursor: pointer;
        }

        /* 登录和注册页面样式 */
        .auth-container {
            padding: 20px;
        }

        .auth-title {
            text-align: center;
            margin-bottom: 20px;
            font-size: 24px;
            color: #333;
        }

        .auth-form {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 1px 5px rgba(0,0,0,0.1);
        }

        .form-group {
            margin-bottom: 15px;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #555;
        }

        .form-input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }

        .auth-button {
            background-color: #1e88e5;
            color: white;
            border: none;
            padding: 12px;
            border-radius: 4px;
            width: 100%;
            font-size: 16px;
            margin-top: 10px;
            cursor: pointer;
        }

        .auth-link {
            text-align: center;
            margin-top: 15px;
            font-size: 14px;
            color: #555;
        }

        .auth-link a {
            color: #1e88e5;
            text-decoration: none;
        }

        /* 简历提交表单样式 */
        .resume-form {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            margin: 15px;
            box-shadow: 0 1px 5px rgba(0,0,0,0.1);
        }

        .form-title {
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 20px;
            color: #333;
        }

        textarea.form-input {
            height: 100px;
            resize: vertical;
        }

        .form-file {
            margin-top: 5px;
        }

        /* 我的页面样式 */
        .profile-container {
            padding: 20px;
        }

        .profile-card {
            background-color: white;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }

        .profile-header {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }

        .profile-avatar {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            background-color: #1e88e5;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            margin-right: 15px;
        }

        .profile-name {
            font-size: 18px;
            font-weight: bold;
        }

        .profile-email {
            color: #777;
            font-size: 14px;
        }

        .menu-item {
            display: flex;
            align-items: center;
            padding: 15px;
            border-bottom: 1px solid #eee;
            color: #333;
        }

        .menu-item:last-child {
            border-bottom: none;
        }

        .menu-icon {
            margin-right: 15px;
            color: #1e88e5;
            font-size: 18px;
            width: 24px;
            text-align: center;
        }

        .menu-title {
            flex: 1;
        }

        .menu-arrow {
            color: #ccc;
        }
    </style>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
</head>
<body>
    <div class="app-container">
        <!-- 主页面 -->
        <div id="main-view">
            <div class="header">
                <h1>职位推荐</h1>
            </div>
            
            <div class="search-container">
                <input type="text" class="search-input" placeholder="搜索职位、公司、地点...">
                <button class="search-button" onclick="searchJobs()">搜索</button>
            </div>
            
            <!-- 就近标签页 -->
            <div id="nearby-tab" class="tab-content active">
                <div id="nearby-jobs-list"></div>
            </div>
            
            <!-- 最新标签页 -->
            <div id="latest-tab" class="tab-content">
                <div id="latest-jobs-list"></div>
            </div>
            
            <!-- 我的标签页 -->
            <div id="profile-tab" class="tab-content">
                <div class="profile-container">
                    <div class="profile-card">
                        <div class="profile-header">
                            <div class="profile-avatar">
                                <i class="fas fa-user"></i>
                            </div>
                            <div>
                                <div class="profile-name" id="profile-name">未登录</div>
                                <div class="profile-email" id="profile-email">请登录查看个人信息</div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="profile-card">
                        <div class="menu-item" onclick="showMyApplications()">
                            <div class="menu-icon"><i class="fas fa-briefcase"></i></div>
                            <div class="menu-title">我的申请</div>
                            <div class="menu-arrow"><i class="fas fa-chevron-right"></i></div>
                        </div>
                        <div class="menu-item" onclick="showFavorites()">
                            <div class="menu-icon"><i class="fas fa-heart"></i></div>
                            <div class="menu-title">收藏职位</div>
                            <div class="menu-arrow"><i class="fas fa-chevron-right"></i></div>
                        </div>
                        <div class="menu-item" onclick="showMyResume()">
                            <div class="menu-icon"><i class="fas fa-file-alt"></i></div>
                            <div class="menu-title">我的简历</div>
                            <div class="menu-arrow"><i class="fas fa-chevron-right"></i></div>
                        </div>
                    </div>
                    
                    <div class="profile-card">
                        <div class="menu-item" onclick="showSettings()">
                            <div class="menu-icon"><i class="fas fa-cog"></i></div>
                            <div class="menu-title">设置</div>
                            <div class="menu-arrow"><i class="fas fa-chevron-right"></i></div>
                        </div>
                        <div class="menu-item" id="login-logout-menu" onclick="handleLoginLogout()">
                            <div class="menu-icon"><i class="fas fa-sign-in-alt"></i></div>
                            <div class="menu-title">登录</div>
                            <div class="menu-arrow"><i class="fas fa-chevron-right"></i></div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 底部导航栏 -->
            <div class="nav-tabs">
                <div class="nav-tab active" onclick="changeTab('nearby-tab', this)">
                    <i class="fas fa-map-marker-alt"></i>
                    就近
                </div>
                <div class="nav-tab" onclick="changeTab('latest-tab', this)">
                    <i class="fas fa-clock"></i>
                    最新
                </div>
                <div class="nav-tab" onclick="changeTab('profile-tab', this)">
                    <i class="fas fa-user"></i>
                    我的
                </div>
            </div>
        </div>
        
        <!-- 职位详情页 -->
        <div id="job-detail-view" style="display: none;">
            <div class="header">
                <span class="back-button" onclick="backToMain()"><i class="fas fa-arrow-left"></i></span>
                <h1>职位详情</h1>
            </div>
            
            <div id="job-detail-content"></div>
        </div>
        
        <!-- 登录页面 -->
        <div id="login-view" style="display: none;">
            <div class="header">
                <span class="back-button" onclick="backToMain()"><i class="fas fa-arrow-left"></i></span>
                <h1>登录</h1>
            </div>
            
            <div class="auth-container">
                <div class="auth-form">
                    <div class="form-group">
                        <label class="form-label">用户名/邮箱</label>
                        <input type="text" class="form-input" id="login-username" placeholder="请输入用户名或邮箱">
                    </div>
                    <div class="form-group">
                        <label class="form-label">密码</label>
                        <input type="password" class="form-input" id="login-password" placeholder="请输入密码">
                    </div>
                    <button class="auth-button" onclick="login()">登录</button>
                    <div class="auth-link">
                        没有账号？<a href="javascript:showRegister()">立即注册</a>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 注册页面 -->
        <div id="register-view" style="display: none;">
            <div class="header">
                <span class="back-button" onclick="showLogin()"><i class="fas fa-arrow-left"></i></span>
                <h1>注册</h1>
            </div>
            
            <div class="auth-container">
                <div class="auth-form">
                    <div class="form-group">
                        <label class="form-label">用户名</label>
                        <input type="text" class="form-input" id="register-username" placeholder="请输入用户名">
                    </div>
                    <div class="form-group">
                        <label class="form-label">邮箱</label>
                        <input type="email" class="form-input" id="register-email" placeholder="请输入邮箱">
                    </div>
                    <div class="form-group">
                        <label class="form-label">密码</label>
                        <input type="password" class="form-input" id="register-password" placeholder="请设置密码">
                    </div>
                    <div class="form-group">
                        <label class="form-label">确认密码</label>
                        <input type="password" class="form-input" id="register-confirm-password" placeholder="请再次输入密码">
                    </div>
                    <button class="auth-button" onclick="register()">注册</button>
                    <div class="auth-link">
                        已有账号？<a href="javascript:showLogin()">返回登录</a>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 简历投递页面 -->
        <div id="resume-view" style="display: none;">
            <div class="header">
                <span class="back-button" onclick="backToJobDetail()"><i class="fas fa-arrow-left"></i></span>
                <h1>投递简历</h1>
            </div>
            
            <div class="resume-form">
                <div class="form-title">申请职位：<span id="apply-job-title"></span></div>
                
                <div class="form-group">
                    <label class="form-label">姓名</label>
                    <input type="text" class="form-input" id="resume-name" placeholder="请输入您的真实姓名">
                </div>
                
                <div class="form-group">
                    <label class="form-label">联系电话</label>
                    <input type="tel" class="form-input" id="resume-phone" placeholder="请输入您的联系电话">
                </div>
                
                <div class="form-group">
                    <label class="form-label">邮箱</label>
                    <input type="email" class="form-input" id="resume-email" placeholder="请输入您的邮箱">
                </div>
                
                <div class="form-group">
                    <label class="form-label">求职意向</label>
                    <input type="text" class="form-input" id="resume-intention" placeholder="请输入您的求职意向">
                </div>
                
                <div class="form-group">
                    <label class="form-label">个人简介</label>
                    <textarea class="form-input" id="resume-introduction" placeholder="请简要介绍您自己"></textarea>
                </div>
                
                <div class="form-group">
                    <label class="form-label">上传简历（PDF格式）</label>
                    <input type="file" class="form-file" id="resume-file" accept=".pdf">
                </div>
                
                <button class="auth-button" onclick="submitResume()">提交申请</button>
            </div>
        </div>
    </div>

    <script>
        // 全局变量
        let currentJobId = null;
        let currentUser = null;
        let jobs = [];
        let myApplications = [];
        let favorites = [];
        
        // 页面加载后初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 检查是否已登录
            checkLoginStatus();
            
            // 获取职位数据
            fetchNearbyJobs();
            fetchLatestJobs();
        });
        
        // 切换标签页
        function changeTab(tabId, element) {
            // 隐藏所有标签页内容
            document.querySelectorAll('.tab-content').forEach(tab => {
                tab.classList.remove('active');
            });
            
            // 显示选中的标签页内容
            document.getElementById(tabId).classList.add('active');
            
            // 更新标签样式
            document.querySelectorAll('.nav-tab').forEach(tab => {
                tab.classList.remove('active');
            });
            element.classList.add('active');
            
            // 如果切换到最新标签页且还没有加载数据，则加载数据
            if (tabId === 'latest-tab' && document.getElementById('latest-jobs-list').innerHTML === '') {
                fetchLatestJobs();
            }
        }
        
        // 从API获取附近职位
         function fetchNearbyJobs() {
            // 模拟获取位置
            const latitude = 31.2304;  // 上海
            const longitude = 121.4737;
            
            // 模拟API请求
            fetch(`http://localhost:3000/jobs/nearby?lat=${latitude}&lng=${longitude}`)
                .then(response => {
                    // 由于是模拟，我们直接返回模拟数据
                    return response.json();
                })
                .then(data => {
                    renderJobs(data.data, 'nearby-jobs-list');
                })
                .catch(error => {
                    console.error('获取附近职位失败:', error);
                    // 加载失败时显示模拟数据
                    //renderJobs(getMockJobs().filter((job, index) => index % 2 === 0), 'nearby-jobs-list');
                });
        }
        
        // 从API获取最新职位
        function fetchLatestJobs() {
            // 模拟API请求
            fetch('http://localhost:3000/jobs/latest')
                .then(response => {
                    // 由于是模拟，我们直接返回模拟数据
                    return response.json();
                })
                .then(data => {
                    renderJobs(data.data, 'latest-jobs-list');
                })
                .catch(error => {
                    console.error('获取最新职位失败:', error);
                    // 加载失败时显示模拟数据
                    //renderJobs(getMockJobs().sort((a, b) => new Date(b.postDate) - new Date(a.postDate)), 'latest-jobs-list');
                });
        }
        
        // 渲染职位列表
        function renderJobs(jobsData, containerId) {
            jobs = jobsData.jobs; // 保存到全局变量中
            const container = document.getElementById(containerId);
            container.innerHTML = '';
            
            if (jobs === undefined || jobs.length === 0 ) {
                container.innerHTML = '<p style="text-align: center; padding: 20px;">暂无职位数据</p>';
                return;
            }

            if (jobs && Array.isArray(jobs)) {
                jobs.forEach(job => {
                    const jobCard = document.createElement('div');
                    jobCard.className = 'job-card';
                    jobCard.onclick = () => showJobDetail(job.id);
                    
                    let tagsHtml = '';
                    job.tags.forEach(tag => {
                        tagsHtml += `<span class="job-tag">${tag}</span>`;
                    });
                    
                    jobCard.innerHTML = `
                        <div class="job-title">${job.title}</div>
                        <div class="job-company">${job.company}</div>
                        <div class="job-details">
                            <span>${job.location}</span>
                            <span>${job.salary}</span>
                        </div>
                        <div class="job-tags">
                            ${tagsHtml}
                        </div>
                    `;
                    
                    container.appendChild(jobCard);
                });
            }
        }
        
        // 显示职位详情
        function showJobDetail(jobId) {
            currentJobId = jobId;
            const job = jobs.find(j => j.id === jobId);
            
            if (!job) {
                alert('职位信息未找到');
                return;
            }
            
            const jobDetailContent = document.getElementById('job-detail-content');
            
            let tagsHtml = '';
            job.tags.forEach(tag => {
                tagsHtml += `<span class="job-tag">${tag}</span>`;
            });
            
            jobDetailContent.innerHTML = `
                <div class="job-detail-container">
                    <div class="job-detail-header">
                        <div class="job-detail-title">${job.title}</div>
                        <div class="job-detail-company">${job.company}</div>
                        <div class="job-detail-salary">${job.salary}</div>
                        <div class="job-detail-info">
                            <span><i class="fas fa-map-marker-alt"></i> ${job.location}</span>
                            <span><i class="fas fa-graduation-cap"></i> ${job.education}</span>
                            <span><i class="fas fa-briefcase"></i> ${job.experience}</span>
                        </div>
                        <div class="job-tags">
                            ${tagsHtml}
                        </div>
                    </div>
                    
                    <div class="job-description">
                        <h3>职位描述</h3>
                        <p>${job.description}</p>
                    </div>
                    
                    <div class="job-requirements">
                        <h3>职位要求</h3>
                        <p>${job.requirements}</p>
                    </div>
                    
                    <button class="apply-button" onclick="applyJob(${job.id})">立即申请</button>
                </div>
            `;
            
            // 隐藏主页面，显示详情页
            document.getElementById('main-view').style.display = 'none';
            document.getElementById('job-detail-view').style.display = 'block';
        }
        
        // 返回主页面
        function backToMain() {
            document.getElementById('main-view').style.display = 'block';
            document.getElementById('job-detail-view').style.display = 'none';
            document.getElementById('login-view').style.display = 'none';
            document.getElementById('register-view').style.display = 'none';
            document.getElementById('resume-view').style.display = 'none';
        }
        
        // 搜索职位
        function searchJobs() {
            const keyword = document.querySelector('.search-input').value.trim();
            
            if (!keyword) {
                alert('请输入搜索关键词');
                return;
            }
            
            // 模拟API搜索请求
            fetch(`http://localhost:3000/jobs/search?keyword=${encodeURIComponent(keyword)}`)
                .then(response => {
                    // 由于是模拟，我们直接筛选本地数据
                    const filteredJobs = getMockJobs().filter(job => 
                        job.title.toLowerCase().includes(keyword.toLowerCase()) || 
                        job.company.toLowerCase().includes(keyword.toLowerCase()) ||
                        job.location.toLowerCase().includes(keyword.toLowerCase())
                    );
                    
                    return {
                        status: 'success',
                        data: filteredJobs
                    };
                })
                .then(data => {
                    // 切换到最近标签页并显示搜索结果
                    changeTab('nearby-tab', document.querySelector('.nav-tab'));
                    renderJobs(data.data, 'nearby-jobs-list');
                })
                .catch(error => {
                    console.error('搜索职位失败:', error);
                    alert('搜索失败，请稍后重试');
                });
        }
        
        // 申请职位
        function applyJob(jobId) {
            // 检查是否已登录
            if (!currentUser) {
                alert('请先登录');
                showLogin();
                return;
            }
            
            const job = jobs.find(j => j.id === jobId);
            if (!job) {
                alert('职位信息未找到');
                return;
            }
            
            // 显示简历投递页面
            document.getElementById('job-detail-view').style.display = 'none';
            document.getElementById('resume-view').style.display = 'block';
            document.getElementById('apply-job-title').textContent = job.title;
            
            // 如果用户有简历信息，自动填充
            if (currentUser.resume) {
                document.getElementById('resume-name').value = currentUser.resume.name || '';
                document.getElementById('resume-phone').value = currentUser.resume.phone || '';
                document.getElementById('resume-email').value = currentUser.email || '';
                document.getElementById('resume-intention').value = currentUser.resume.intention || '';
                document.getElementById('resume-introduction').value = currentUser.resume.introduction || '';
            }
        }
        
        // 返回职位详情
        function backToJobDetail() {
            document.getElementById('resume-view').style.display = 'none';
            document.getElementById('job-detail-view').style.display = 'block';
        }
        
        // 提交简历
        function submitResume() {
            // 获取表单数据
            const name = document.getElementById('resume-name').value.trim();
            const phone = document.getElementById('resume-phone').value.trim();
            const email = document.getElementById('resume-email').value.trim();
            const intention = document.getElementById('resume-intention').value.trim();
            const introduction = document.getElementById('resume-introduction').value.trim();
            const resumeFile = document.getElementById('resume-file').files[0];
            
            // 验证表单
            if (!name || !phone || !email) {
                alert('请填写必要的个人信息');
                return;
            }
            
            if (!resumeFile && !introduction) {
                alert('请上传简历或填写个人简介');
                return;
            }
            
            // 模拟API提交
            const formData = new FormData();
            formData.append('jobId', currentJobId);
            formData.append('userId', currentUser.id);
            formData.append('name', name);
            formData.append('phone', phone);
            formData.append('email', email);
            formData.append('intention', intention);
            formData.append('introduction', introduction);
            if (resumeFile) {
                formData.append('resumeFile', resumeFile);
            }
            
            // 模拟API请求
            console.log('提交简历数据', Object.fromEntries(formData));
            
            // 添加到我的申请列表
            const job = jobs.find(j => j.id === currentJobId);
            myApplications.push({
                id: Date.now(),
                jobId: currentJobId,
                jobTitle: job.title,
                company: job.company,
                applyDate: new Date().toISOString(),
                status: '待处理'
            });
            
            // 保存用户简历信息
            if (!currentUser.resume) {
                currentUser.resume = {};
            }
            currentUser.resume.name = name;
            currentUser.resume.phone = phone;
            currentUser.resume.intention = intention;
            currentUser.resume.introduction = introduction;
            
            // 保存到本地存储
            localStorage.setItem('currentUser', JSON.stringify(currentUser));
            localStorage.setItem('myApplications', JSON.stringify(myApplications));
            
            alert('简历提交成功！');
            backToMain();
        }
        
        // 显示登录页面
        function showLogin() {
            document.getElementById('main-view').style.display = 'none';
            document.getElementById('job-detail-view').style.display = 'none';
            document.getElementById('register-view').style.display = 'none';
            document.getElementById('login-view').style.display = 'block';
        }
        
        // 显示注册页面
        function showRegister() {
            document.getElementById('login-view').style.display = 'none';
            document.getElementById('register-view').style.display = 'block';
        }
        
        // 登录
        function login() {
            const username = document.getElementById('login-username').value.trim();
            const password = document.getElementById('login-password').value.trim();
            
            if (!username || !password) {
                alert('请输入用户名和密码');
                return;
            }
            
            // 模拟API登录请求
            fetch('http://localhost:3000/user/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ username, password })
            })
            .then(response => {
                // 由于是模拟，我们直接返回成功
                if (username === 'demo' && password === 'password') {
                    return {
                        status: 'success',
                        data: {
                            id: 1,
                            username: 'demo',
                            email: 'demo@example.com',
                            resume: {
                                name: '张三',
                                phone: '13800138000',
                                intention: '前端开发工程师',
                                introduction: '3年前端开发经验，精通HTML、CSS、JavaScript'
                            }
                        }
                    };
                } else {
                    throw new Error('用户名或密码错误');
                }
            })
            .then(data => {
                currentUser = data.data;
                localStorage.setItem('currentUser', JSON.stringify(currentUser));
                
                // 更新用户信息显示
                updateUserProfile();
                
                alert('登录成功');
                backToMain();
            })
            .catch(error => {
                console.error('登录失败:', error);
                alert(error.message || '登录失败，请检查用户名和密码');
            });
        }
        
        // 注册
        function register() {
            const username = document.getElementById('register-username').value.trim();
            const email = document.getElementById('register-email').value.trim();
            const password = document.getElementById('register-password').value.trim();
            const confirmPassword = document.getElementById('register-confirm-password').value.trim();
            
            if (!username || !email || !password) {
                alert('请填写完整的注册信息');
                return;
            }
            
            if (password !== confirmPassword) {
                alert('两次输入的密码不一致');
                return;
            }
            
            // 模拟API注册请求
            fetch('http://localhost:3000/user/register', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ username, email, password })
            })
            .then(response => {
                // 由于是模拟，我们直接返回成功
                return {
                    status: 'success',
                    data: {
                        id: Date.now(),
                        username,
                        email
                    }
                };
            })
            .then(data => {
                alert('注册成功，请登录');
                showLogin();
                
                // 自动填充登录表单
                document.getElementById('login-username').value = username;
            })
            .catch(error => {
                console.error('注册失败:', error);
                alert('注册失败，请稍后重试');
            });
        }
        
        // 检查登录状态
        function checkLoginStatus() {
            const userData = localStorage.getItem('currentUser');
            if (userData) {
                currentUser = JSON.parse(userData);
            } else {
                currentUser = null;
            }
        }
    </script>
</body>
</html> 